import {Service, action} from "adajs";
import CommentList from "../../lists/comment";

class NewsService extends Service {
    defaultData() {
        return {
            isLoad: false,
            newsInfo: {
                "id": "",
                "title": "",
                "dzbid": "",
                "crtUser": "",
                "crtTime": "",
                "nr": "",
                "fjid": ""
            },
            id: "",
            list: {
                url: "/api/lgb/app/lgb/branchexchangemsg/queryPage",
                type: CommentList,
                parameter: {
                    themeId: '',
                    t: new Date()
                }
            }
        };
    }

    onupdate(current, id) {
        if (id) {
            return this.context.request.get("/api/lgb/app/lgb/branchexchange/get", {id}).then(({data}) => {
                current.id = id;
                current.isLoad = true;
                current.newsInfo = data;
                current.list.parameter.themeId = id;
            });
        }
    }

    @action("refresh")
    refresh(current) {
        current.list.parameter.t = new Date();
    }
}

export default NewsService;